home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 May / SGI IRIX 6.5 Applications 1999 May.iso / dist / demos.idb / usr / demos / Demo_Interfaces / Buttonfly / bf_menu.pl.z / bf_menu.pl
Encoding:
Perl Script  |  1999-04-09  |  10.6 KB  |  331 lines

  1. #!/usr/sbin/perl
  2.  
  3. #**************************************************************************
  4. #*                                                                        *
  5. #*            Copyright (c) 1996 Silicon Graphics, Inc.                   *
  6. #*                      All Rights Reserved                               *
  7. #*                                                                        *
  8. #*         THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI             *
  9. #*                                                                        *
  10. #* The copyright notice above does not evidence any actual of intended    *
  11. #* publication of such source code, and is an unpublished work by Silicon *
  12. #* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
  13. #* the property of Silicon Graphics, Inc. Any use, duplication or         *
  14. #* disclosure not specifically authorized by Silicon Graphics is strictly *
  15. #* prohibited.                                                            *
  16. #*                                                                        *
  17. #* RESTRICTED RIGHTS LEGEND:                                              *
  18. #*                                                                        *
  19. #* Use, duplication or disclosure by the Government is subject to         *
  20. #* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in   *
  21. #* Technical Data and Computer Software clause at DFARS 52.227-7013,      *
  22. #* and/or in similar or successor clauses in the FAR, DOD or NASA FAR     *
  23. #* Supplement. Unpublished - rights reserved under the Copyright Laws of  *
  24. #* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.       *
  25. #* Shoreline Blvd., Mountain View, CA 94039-7311                          *
  26. #**************************************************************************
  27.  
  28. # bf_menu.pl
  29. #
  30. # Script for generating buttonfly menus
  31.  
  32. # Parse input
  33. $main_switch = shift @ARGV;
  34. $sub_switch = join(" ", @ARGV);
  35.  
  36. # Includes
  37. $PATH_WEB_CGI         = "/usr/demos/Demo_Interfaces/Web/cgi-scripts";
  38. $PATH_BUTTON_DIR    = "/usr/demos/Demo_Interfaces/Buttonfly";
  39. require "$PATH_WEB_CGI/DEMO_includes.pl";
  40. require "$PATH_BUTTON_DIR/bf_const.pl";
  41.  
  42. # Read Tables
  43. &Read_Tables;
  44.  
  45. # Main switch
  46. if ("$main_switch" eq "$SWITCH_INFO") {    
  47.     &Run_Information;
  48. } elsif ("$main_switch" eq "$SWITCH_SUB_CAT") {
  49.     &Print_Sub_Cat_Menu_Page;
  50. } elsif ("$main_switch" eq "$SWITCH_CAT") {
  51.     &Print_Cat_Menu_Page;
  52. } elsif ("$main_switch" eq "$SWITCH_TREE_MENU") {
  53.     &Print_Trees_Page;
  54. } elsif ("$main_switch" eq "$SWITCH_MENU") {
  55.     &Print_Tree_List_Page;
  56. } elsif ("$main_switch" eq "$SWITCH_RELATED") {
  57.     &Print_Related_Demo;
  58. } elsif ("$main_switch" eq "$SWITCH_MAN") {
  59.     &Run_Man_Page;
  60. } elsif ("$main_switch" eq "$SWITCH_FIND_DEMO") {
  61.     &Run_Find_Demo;
  62. } elsif ("$main_switch" eq "$SWITCH_HOW_TO") {
  63.     &Run_How_To;
  64. } elsif ("$main_switch" eq "$SWITCH_PARTIAL") {
  65.     &Print_Partial;
  66. } else {
  67.     &Print_Top_Page;
  68. }
  69.  
  70. sub Run_How_To {
  71.     `$CMD_XCONFIRM $CMD_XCONFIRM_FLAGS $CMD_XCONFIRM_FILE "$FILE_BUTTONFLY_INFO"$CMD_NULLIFY$CMD_BACKGROUND`;
  72. }
  73.  
  74.  
  75. sub Print_Sub_Cat_Menu_Page {
  76.     ($sub_cat,$cat) = split(/$TREES_DELIM/, $sub_switch);
  77.     &Source_Table($FILE_TABLE_FEATURES, @features_categories) if ("$cat" eq "$SWITCH_FEATURES");
  78.     &Source_Table($FILE_TABLE_MARKETS, @markets_categories)  if ("$cat" eq "$SWITCH_MARKETS");
  79.     &Source_Table($FILE_TABLE_HARDWARE, @hardware_categories) if ("$cat" eq "$SWITCH_HARDWARE");
  80.     @demos = split(/$TABLE_SECOND_DELIM/, $demos_under{$sub_cat});
  81.     if ($#demos > $BF_MAX_DEMOS) { # Too many demos for buttonfly to handle
  82.         &Print_Split_Page(@demos);
  83.     } else {
  84.         for $demo (&alpha(@demos)) {
  85.             ($demo_name, $demo_tree) = split(/$TREES_DELIM/, $demo);
  86.             &Print_Demo_Button("$demo", "$demo_name");
  87.         }
  88.     }
  89. }
  90.  
  91. sub Print_Split_Page {
  92.     local(@a_demos) = &alpha(@_);
  93.     local($done) = 0;
  94.     foreach $i ( 0..$#a_demos ) {
  95.         if ($i > ($BF_MAX_DEMOS-1) && ($done == 0)) {
  96.             &Print_More_Button(@a_demos[$i..$#a_demos]);
  97.             $done = 1 ;
  98.         } else {
  99.             if ($done == 0) {
  100.                 ($demo_name, $demo_tree) = split(/$TREES_DELIM/, $a_demos[$i]);
  101.                 &Print_Demo_Button("$a_demos[$i]", "$demo_name");
  102.             }
  103.         }
  104.     }
  105. }
  106.  
  107. sub Print_Partial {
  108.     local(@demos) = split('\+', $sub_switch);
  109.     local(@a_demos) = &alpha(@demos);
  110.     $done = 0;
  111.     foreach $i (0..$#a_demos) {
  112.         if ($i > ($BF_MAX_DEMOS-1) && $done == 0) {
  113.             &Print_More_Button(@a_demos[$i..$#a_demos]);
  114.             $done = 1;
  115.         } else {    
  116.             if ($done == 0) {
  117.                 ($demo_name, $demo_tree) = split(/$TREES_DELIM/, $a_demos[$i]);
  118.                 &Print_Demo_Button("$a_demos[$i]", "$demo_name");
  119.             }
  120.         }
  121.     }
  122. }
  123.  
  124. sub Print_More_Button {
  125.     local(@demos) = @_;
  126.     local($demo_list) = join('+', @demos);
  127.     print "More Demos...\n";
  128.     print "\t$FILE_BUTTONFLY_SCRIPT $SWITCH_PARTIAL $demo_list\n";
  129.     print "\t.menu. -\n";
  130.     print "\t.popup. $_[1] \%t\n";
  131.     print "\t.color. $COLOR_NORM\n";
  132.     print "\t.highcolor. $COLOR_HIGH\n";
  133. }
  134.         
  135. sub Print_Cat_Menu_Page {
  136.     &Read_Tables;
  137.     &Source_Table($FILE_TABLE_FEATURES, @features_categories) if ("$sub_switch" eq "$SWITCH_FEATURES");
  138.     &Source_Table($FILE_TABLE_MARKETS, @markets_categories) if ("$sub_switch" eq "$SWITCH_MARKETS");
  139.     &Source_Table($FILE_TABLE_HARDWARE, @hardware_categories) if ("$sub_switch" eq "$SWITCH_HARDWARE");
  140.     for ( &alpha(keys(%demos_under)) ) {
  141.         &Print_Button("$SWITCH_SUB_CAT $_$TREES_DELIM$sub_switch", "$_") if ("$demos_under{$_}" ne "");
  142.     }
  143. }
  144.  
  145. sub Run_Information {
  146.     ($demo_name, $demo_tree) = split(/$TREES_DELIM/, $sub_switch);
  147.     $tree_path = &Tree_Path_From_Name("$demo_tree");
  148.     &Parse_Demo_Info("$tree_path/$demo_name/$DEMOSRC_INDEX");
  149.     open(TMP, ">$FILE_INFO_TMP");
  150.     print TMP "$demo_info{'DESCRIPTION'}\n";
  151.     close(TMP);
  152.     `$CMD_FMT -60 $FILE_INFO_TMP>$FILE_INFO_TMP2`;
  153.     `$CMD_XCONFIRM $CMD_XCONFIRM_FILE "$FILE_INFO_TMP2" $CMD_XCONFIRM_FLAGS`;
  154.     `$CMD_RM $FILE_INFO_TMP <<y`;
  155.     `$CMD_RM $FILE_INFO_TMP2 <<y`;
  156. }
  157.  
  158. sub Run_Man_Page {
  159.     ($demo_name, $demo_tree) = split(/$TREES_DELIM/, $sub_switch);
  160.     &Display_Man_Page("$demo_name");
  161. }
  162.  
  163. sub Print_Tree_List_Page {
  164.     local($demo_name, $demo_tree, @demos);
  165.     @demos = &Demos_In_Tree("$sub_switch");
  166.     if ($#demos > $BF_MAX_DEMOS) {
  167.          foreach $i  (0..$#demos) {
  168.             local($demo_str)  = "$demos[$i]$TREES_DELIM$sub_switch";    
  169.             $demos[$i] = $demo_str;    
  170.         }
  171.         &Print_Split_Page(@demos);
  172.     } else {    
  173.         for (@demos) {
  174.             &Print_Demo_Button("$_$TREES_DELIM$sub_switch", "$_");
  175.         }
  176.     }
  177. }
  178.  
  179. sub Get_User_Input {
  180.     local($user_input, $buf);
  181.     undef $user_input;
  182.     undef $buf;
  183.     #system("$CMD_LAUNCH -h echo -m \"Demo Name:\" > $FILE_SEARCH_TMP");
  184.     open(FILE, "$CMD_LAUNCH -h echo -m \"Demo Name:\"|");
  185.     #open(FILE, "$FILE_SEARCH_TMP");
  186.     while(<FILE>) {
  187.         #print "$_\n";
  188.         $user_input .= $_;
  189.     }
  190.     close(FILE);
  191.     `$CMD_RM $FILE_SEARCH_TMP`;
  192.     chop $user_input;
  193.     return($user_input);
  194. }
  195.  
  196. sub Run_Find_Demo {
  197.  
  198.         ## Bob Penrod 02 December 1997
  199.         ## fork this process so we don't block the parent buttonfly proc
  200.         ## if fork returns a non-zero value, we're the parent, so quit. 
  201.         if ( fork() != 0 ) { return; } 
  202.  
  203.     $user_input = &Get_User_Input;
  204.     @results = &Find_Demos_By_Title("$user_input");
  205.     if (@results) {
  206.         ## Bob Penrod 02 December 1997
  207.         ## Open a pipe to a new buttonfly proc and write a menu to it
  208.             open (BF_IN, "| $PATH_BUTTON_DIR/buttonfly -");
  209.         print BF_IN "\t.backcolor. .45 .45 .69\n";
  210.         local ($std_out) = *STDOUT; ## Save ref to orig STDOUT
  211.                 *STDOUT = BF_IN;            ## Redirect STDOUT to buttonfly
  212.         for $demo (@results) {
  213.             ($demo_name, $demo_tree) = split(/$HTTP_TREES_DELIM/, $demo);
  214.             $demo_tree =~ s/\+/ /g; 
  215.             &Print_Demo_Button("$demo_name$TREES_DELIM$demo_tree", "$demo_name");
  216.         }
  217.         close(BF_IN);        ## close buttonfly pipe
  218.         *STDOUT = $std_out;  ## Restore original STDOUT
  219.     } else {
  220.         open(CMD, "$CMD_XCONFIRM -header \"$TITLE_FIND_DEMO\" -B OK -b Search -icon info -t \"Demo not found: $user_input\"|");
  221.         read(CMD, $answer, 100);
  222.         close(CMD);
  223.         chop $answer;    
  224.         &Run_Find_Demo if ( "$answer" eq "Search" );
  225.     }
  226. }
  227.  
  228. sub Print_Button {
  229.     print "$_[1]\n";
  230.     print "\t$FILE_BUTTONFLY_SCRIPT $_[0]\n";
  231.     print "\t.menu. -\n";
  232.     print "\t.popup. $_[1] \%t\n";
  233.     print "\t.color. $COLOR_NORM\n";
  234.     print "\t.highcolor. $COLOR_HIGH\n";
  235. }
  236.  
  237. sub Print_Demo_Button {
  238.     ($demo_name, $demo_tree) = split(/$TREES_DELIM/, $_[0]);
  239.     $demo_path = &Tree_Path_From_Name("$demo_tree");
  240.     chdir("$demo_path");
  241.     opendir(DIR, "$demo_path/$demo_name");
  242.     @menus = grep(/\.m_.*/, readdir(DIR));
  243.     closedir(DIR);
  244.     if (@menus) {
  245.         print "$_[1]\n";
  246.         print "\t$FILE_BUTTONFLY_SCRIPT $SWITCH_RELATED $_[0]\n";
  247.         print "\t.menu. -\n";
  248.         print "\t.popup. $_[1] \%t\n";
  249.         print "\t.color. $COLOR_NORM\n";
  250.         print "\t.highcolor. $COLOR_HIGH\n";
  251.     } else {
  252.         print "$_[1]\n";
  253.         print "\t.cd. $demo_path/$demo_name\n";
  254.         print "\t$demo_path/$demo_name/$DEMOSRC_RUN\n";
  255.         print "\t.popup. $_[1] \%t\n";
  256.         print "\t.popup. Information\n";
  257.         print "\t$FILE_BUTTONFLY_SCRIPT $SWITCH_INFO $_[0]\n";
  258.         print "\t.popup. Manual\n";
  259.         print "\t$FILE_BUTTONFLY_SCRIPT $SWITCH_MAN $_[0]\n";
  260.         print "\t.color. $COLOR_NORM_END\n";
  261.         print "\t.highcolor. $COLOR_HIGH_END\n";
  262.     }
  263. }
  264.  
  265.  
  266. sub Print_Related_Demo {
  267.     ($demo_name, $demo_tree) = split(/$TREES_DELIM/, $sub_switch);
  268.     $demo_path = &Tree_Path_From_Name("$demo_tree");
  269.     chdir("$demo_path");
  270.     opendir(DIR, "$demo_path/$demo_name");
  271.     @menus = grep(/\.m_.*/, readdir(DIR));
  272.     closedir(DIR);
  273.     print "$demo_name\n";
  274.     print "\t.cd. $demo_path/$demo_name\n";
  275.     print "\t$demo_path/$demo_name/$DEMOSRC_RUN\n";
  276.     print "\t.popup. $demo_name \%t\n";
  277.     print "\t.popup. Information\n";
  278.     print "\t$FILE_BUTTONFLY_SCRIPT $SWITCH_INFO $sub_switch\n";
  279.     print "\t.popup. Manual\n";
  280.     print "\t$FILE_BUTTONFLY_SCRIPT $SWITCH_MAN $sub_switch\n";
  281.     print "\t.color. $COLOR_NORM_END\n";
  282.     print "\t.highcolor. $COLOR_HIGH_END\n";
  283.     foreach $menu (@menus) {
  284.         open(MENU, "$demo_path/$demo_name/$menu");
  285.         while (<MENU>) {
  286.             print "$_";
  287.         }
  288.         close(MENU);
  289.     }
  290. }
  291.  
  292. sub Print_Trees_Page {
  293.     local(@trees);
  294.     @trees = &List_Tree_Names;
  295.     for (@trees) {
  296.         &Print_Button("$SWITCH_MENU $_", "$_");
  297.     }
  298. }
  299.  
  300. sub Print_Add_Ons {
  301.     local(@allfiles, @alldirs, @dirs);
  302.     chdir("$PATH_DEMO_DIR");
  303.     opendir(DIR, "$PATH_ADDONS_DIR");
  304.     @allfiles = readdir(DIR);
  305.     closedir(DIR);
  306.     for (@allfiles) {
  307.         push(@alldirs, $_) if chdir("$PATH_ADDONS_DIR/$_");
  308.     }
  309.     @dirs = grep(!/^\.\.?$/, @alldirs);
  310.     for (@dirs) {
  311.         print "$_\n";
  312.         print "\t.cd. $PATH_ADDONS_DIR/$_\n";
  313.         print "\tcat ./.m*\n";
  314.         print "\t.menu. -\n";
  315.         print "\t.popup. $_ %t\n";
  316.         print "\t.color. $COLOR_NORM\n";
  317.         print "\t.highcolor. $COLOR_HIGH\n";
  318.     }
  319. }
  320.  
  321. sub Print_Top_Page {
  322.     &Print_Button("$SWITCH_CAT $SWITCH_FEATURES",  "$TITLE_FEATURES");
  323.     &Print_Button("$SWITCH_CAT $SWITCH_MARKETS",   "$TITLE_MARKETS");
  324.     &Print_Button("$SWITCH_TREE_MENU", "$TITLE_TREE_MENU");
  325.     &Print_Button("$SWITCH_FIND_DEMO", "$TITLE_FIND_DEMO");
  326.     &Print_Button("$SWITCH_CAT $SWITCH_HARDWARE",  "$TITLE_HARDWARE");
  327.     &Print_Add_Ons;
  328. }
  329.  
  330.  
  331.